package cn.itmantzy.user.controller;

import cn.itmantzy.basic.exception.BusinessException;
import cn.itmantzy.basic.util.AjaxResult;
import cn.itmantzy.user.dto.LoginDto;
import cn.itmantzy.user.service.ILoginService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 登录接口
 */
@RestController
@RequestMapping("/login")
@Api(tags = "登录接口",description = "登录接口详细描述")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("/account")
    public AjaxResult loginAccount(@RequestBody LoginDto dto){
        try {
            Map<String, Object> map = loginService.loginAccount(dto);
            return AjaxResult.getAjaxResult().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，程序员正在全力抢修！！！");
        }
    }

}
